define(['layer', 'curveLine'], function (layer, curveLine) {
    return {
        init: function () {
            load();
        }
    }
});
var map;//地图
var overlays = new Array();//绘制之后的区域
/**初始化加载*/
function load() {
    map = new BMap.Map("container"); //初始化地图
    map.enableScrollWheelZoom();//启动滚动缩进
    getEnetrAreaList();//获取指定地点位置
    getPositionNowList();//按照条件进行查询出对应的人员最新的数据-
}

/**
 *通过从后台获取最新人员坐标添加标注
 */
function getPositionNowList() {
    $.ajax({
        url: "/map/getPositionNowList",
        dataType: "json",
        type: "post",
        data: {
            "phoneNum": $("#phoneNum").val(),//人员的电话
        },
        success: function (result) {
            var data = result.data;
            addMarker(data);
        }
    })
}
/**
 * 获取指定地点位置
 */
var enetrAreaAry = [];//所有指定地点位置的数组
function getEnetrAreaList() {
    $.ajax({
        url: "/alarmEnterAreaController/findAll",
        dataType: "json",
        type: "post",
        data: {},
        success: function (result) {
            enetrAreaAry = result.data;
            //console.log(enetrAreaAry);
        }
    })
}
/**
 *通过坐标在地图上添加标注
 * @param data
 */
var curveLineList = [];
function addMarker(data) {
    $.each(data, function (index, obj) {
        var point = new BMap.Point(obj.lng, obj.lat);
        //设置地图中心点
        map.centerAndZoom(point, 15);
        var marker;
        //添加标注
        marker = new BMap.Marker(point, {
            icon: new BMap.Icon("/images/icon/renwu.png", new BMap.Size(32, 32))
        });
        map.addOverlay(marker);
        // 随机向地图添加25个标注
        var bounds = map.getBounds();
        var sw = bounds.getSouthWest();
        var ne = bounds.getNorthEast();
        var lngSpan = Math.abs(sw.lng - ne.lng);
        var latSpan = Math.abs(ne.lat - sw.lat);
        for (var i = 0; i < 5; i++) {
            var curveLineArr = [];
            var predictPoint = new BMap.Point(sw.lng + lngSpan * (Math.random() * 0.8), ne.lat - latSpan * (Math.random() * 0.8));
            var markerPoint;
            var iconVariable
            var probability = ((Math.random() * 0.8) * 100).toFixed(2)
            var label

            if (probability < 20) {
                iconVariable = new BMap.Icon("/images/icon/yuce5.png", new BMap.Size(16, 16))
                label = new BMap.Label(probability + "%", {offset: new BMap.Size(0, -16)});
            } else if(probability > 20&& probability <40){
                iconVariable = new BMap.Icon("/images/icon/yuce4.png", new BMap.Size(24, 24))
                label = new BMap.Label(probability + "%", {offset: new BMap.Size(0, -15)});
            }else if(probability > 40&& probability <60){
                iconVariable = new BMap.Icon("/images/icon/yuce3.png", new BMap.Size(32, 32))
                label = new BMap.Label(probability + "%", {offset: new BMap.Size(0, -14)});
            }else if(probability > 60&& probability <80){
                iconVariable = new BMap.Icon("/images/icon/yuce2.png", new BMap.Size(40, 40))
                label = new BMap.Label(probability + "%", {offset: new BMap.Size(0, -16)});
            }else{
                iconVariable = new BMap.Icon("/images/icon/yuce1.png", new BMap.Size(48, 48))
                label = new BMap.Label(probability + "%", {offset: new BMap.Size(0, -18)});
            }
            //添加标注
            markerPoint = new BMap.Marker(predictPoint, {
                icon:iconVariable
            });
            label.setStyle({
                border: "1px solid rgb(204, 204, 204)",
                borderRadius: "10px",
                maxWidth: "100px",
                background: "rgb(255, 255, 255)",
            });
            markerPoint.setLabel(label);
            map.addOverlay(markerPoint);
            curveLineArr.push(point, predictPoint);
            curveLineList.push(curveLineArr)
        }
        $.each(curveLineList, function (index, obj) {
            var curve = new BMapLib.CurveLine(obj, {strokeColor: "blue", strokeWeight: 3, strokeOpacity: 0.5}); //创建弧线对象
            map.addOverlay(curve); //添加到地图中
        })
        //通过当前位置与指定地点位置判断距离
        $.each(enetrAreaAry, function (index, obj) {

        })
    })
}

